<template>
<view>
<!-- 轮播 -->
<view class="banner">
  <swiper :autoplay="autoplay" :interval="interval" :duration="duration" :indicator-dots="bannerLength" circular="true" indicator-color="rgba(255,255,255,0.6)" indicator-active-color="#FF4444">
    <block v-for="(item, index) in shopInfoList.pic" :key="index">
      <swiper-item @tap="banner" :data-index="index">
        <image :src="item.big" class="slide-image"></image>
      </swiper-item>
    </block>
  </swiper>
</view>
<!-- 商品标题 -->
<view class="title-warp">
  <view class="title">{{shopInfoList.name}}</view>
  <view class="moneyInfo">
    <view>
      <view class="newPrice">￥
        <text>{{shopInfoList.group_price}}</text>
      </view>
      <view class="oldPrice">￥{{shopInfoList.mktprice}}</view>
    </view>
    <view>
      <view>
        <text style="color:#E51F54">{{shopInfoList.group_need_num}}</text>人团</view>
      <view class="lines">|</view>
      <view>已售
        <text style="color:#E51F54">{{shopInfoList.sold}}</text>件</view>
    </view>
  </view>
</view>
<!-- 拼团玩法 -->
<view class="group-warp">
  <view class="group-tit">
    <view class="group-line"></view>
    <view class="tit-pic">
      <image src="/static/remao_shop/img/lingxing_icon.png"></image>
    </view>
    <view class="tit-cont">
      <text>拼团玩法</text>
    </view>
    <view class="tit-pic">
      <image src="/static/remao_shop/img/lingxing_icon.png"></image>
    </view>
    <view class="group-line"></view>
  </view>
  <view class="list-warp">
    <view class="start-group list">
      <image src="/static/remao_shop/img/zhifu_icon.png"></image>
      <text>支付开团\n或者参团</text>
    </view>
    <view class="start-group list">
      <image src="/static/remao_shop/img/please_icon.png"></image>
      <text>邀请好友\n参团</text>
    </view>
    <view class="start-group list">
      <image src="/static/remao_shop/img/fahuo_icon.png"></image>
      <text>人数达到\n分别发货</text>
    </view>
    <view class="start-group list">
      <image src="/static/remao_shop/img/tuikuan_icon.png"></image>
      <text>人数不够\n自动退款</text>
    </view>
  </view>
</view>
<!-- 拼团列表 -->
<view class="assemble" v-if="isCloseAssemble">
  <view class="assembleTitle">
    <view>{{arrList.length}}人正在开团，可直接参与</view>
    <view style="margin-right:20rpx" @tap.stop="isOpenAssemble">
      <text>查看更多</text>
      <image src="/static/remao_shop/img/arrow_icon.png"></image>
    </view>
  </view>
  <!-- 一人团 -->
  <view class="assembleNav" v-if="arrList.length == 1">
    <block>
      <view class="assembleNav-list">
        <view class="assembleNavList-left">
          <image :src="arrList[0].avatar"></image>
          <text>{{arrList[0].nickname}}</text>
        </view>
        <view class="assembleNavList-right">

          <view class="assemblebox1">
            <view>还差
              <text style="color:#A53533">{{arrList[0].need}}人</text>成团</view>
            <view class="time_tt">
              <view v-if="isOver" class="time" style="color:#D5D5D5;font-size:20rpx;">
                <view>剩余</view>
                <view class="endTime">
                  <view>{{overTime[0]}}</view>:
                  <view>{{overTime[1]}}</view>:
                  <view>{{overTime[2]}}</view>
                </view>
              </view>
              <view v-if="!isOver" class="time">
                <view>00：00:00</view>
              </view>
            </view>
          </view>
          <view class="assemblebox2" @tap.stop="joinAssemble" :data-id="arrList[0].order_id">去参团</view>
        </view>
      </view>
    </block>
  </view>

  <view class="assembleNav" v-if="arrList.length != 1">
    <swiper :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="interval" :duration="duration" :circular="circular" :vertical="vertical">
      <block v-for="(item, index) in arrListArray" :key="index">
        <swiper-item>
          <view v-for="(items, indexs) in item" :key="indexs" class="assembleNav-list">
            <view class="assembleNavList-left">
              <image :src="items.avatar"></image>
              <text>{{items.nickname}}</text>
            </view>
            <view class="assembleNavList-right">

              <view class="assemblebox1">
                <view>还差
                  <text style="color:#A53533">{{items.need}}人</text>成团</view>
                <view class="time_tt">
                  <view v-if="isOver" class="time" style="color:#D5D5D5;font-size:20rpx;">
                    <view>剩余</view>
                    <view class="endTime">
                      <view>{{overTime[0]}}</view>:
                      <view>{{overTime[1]}}</view>:
                      <view>{{overTime[2]}}</view>
                    </view>
                  </view>
                  <view v-if="!isOver" class="time">
                    <view>00：00:00</view>
                  </view>
                </view>
              </view>
              <view class="assemblebox2" @tap.stop="joinAssemble" :data-id="items.order_id">去参团</view>
            </view>
          </view>
        </swiper-item>
      </block>
    </swiper>
  </view>
</view>
<view class="assemble" v-if="!isCloseAssemble">
  <view class="noAssemble">还没有人去开团，赶紧去开一个吧！</view>
</view>
<!-- 显示全部拼团列表 -->
<view class="assembleList" @tap.stop="isOpenAssemble" v-if="isAssemble">
  <view class="assembleList-nav" @tap.stop="kong">
    <view class="assembleListNav-title">正在开团</view>
    <view class="assembleListNav-list">
      <scroll-view scroll-y="true" class="scroll">
        <view v-for="(item, index) in arrList" :key="index" class="assembleListNavList-s">
          <image mode="widthFix" :src="item.avatar"></image>
          <view class="assembleCart-title">
            <view>{{item.nickname}}</view>
            <!-- <view>还差{{item.need}}人成团，剩余
              <text style="color:#A53533">10:10:10</text> 结束</view> -->
              <view class="time_tt">
                  <view v-if="isOver" class="time" style="color:#D5D5D5;font-size:20rpx;">
                    <view>还差{{item.need}}人成团，剩余</view>
                    <view class="endTime" style="color:#A53533">
                      <view>{{overTime[0]}}</view>:
                      <view>{{overTime[1]}}</view>:
                      <view>{{overTime[2]}}</view>
                    </view>
                    <view>结束</view>
                  </view>
                  <view v-if="!isOver" class="time">
                    <view>00：00:00</view>
                  </view>
                </view>
          </view>
          <view class="assembleCart-join" @tap.stop="joinAssemble" :data-id="item.order_id">去参团</view>
        </view>
      </scroll-view>
    </view>
    <view class="assembleListNav-bottom"></view>
  </view>
</view>
<!-- 详情&评价 -->
<view class="appraise-warp">
  <!-- tab选项卡 -->
  <view class="newbox1">
    <view v-for="(item, index) in navList" :key="index" @tap="getStatus" :id="'NAV' + index" class="appraise-title" :data-index="index">
      <view @tap="EventHandle">
        <text :class="index === status ? 'active' : ''">{{item}}</text>
      </view>
    </view>
  </view>
  <view class="newbox2">
    <!-- 详情 -->
    <view :hidden="status!==0" class="particulars-warp">
      <view class="particulars">
        <rich-text :nodes="shopInfoList.intro"></rich-text>
      </view>
    </view>
    <!-- 评价 -->
    <view :hidden="status!==1" class="particulars-warp">
      <view v-for="(item, i) in shopInfoList.comments" :key="i" class="appraise">
        <view class="appraise-pic">
          <image :src="item.touxiang"></image>
        </view>
        <view class="appraise-name">
          <text>{{item.author_name}}</text>
        </view>
        <view class="appraise-star fr">
          <image v-for="(item, index) in starNum[i]" :key="index" src="/static/remao_shop/img/startOn.png"></image>
        </view>
        <view class="appraise-time">
          <text>{{item.time}}</text>
        </view>
        <view class="appraise-cont">
          <text>{{item.comment}}</text>
        </view>
        <view class="cont-pic list" v-if="item.haspic==1">
          <image v-for="(items, indexImg) in item.pics" :key="indexImg" @tap.stop="lookPics" mode="aspectFill" :data-index="i" :data-indexs="indexImg" :src="items"></image>
        </view>
      </view>
    </view>
  </view>
</view>
<!-- 底部操作 -->
<view :class="system?'bottom-warp':'bottom-warp2'">
  <view class="left">
    <!--<view class='left-head fl'>
      <image src='../../img/Headphones_icon.png'></image>
    </view>-->
    <view class="line"></view>
    <view class="left-col">
      <view @tap="changepic">
        <view>
          <image src="/static/remao_shop/img/shouye.png"></image>
        </view>
        <!-- <view wx:if='{{showView}}'>
          <image src='../../img/mine-shoucang_icon.png'></image>
        </view>
        <view wx:if='{{!showView}}'>
          <image src='../../img/xq-yishoucang_icon.png'></image>
        </view> -->
      </view>
    </view>
  </view>
  <view class="middle" @tap="popupshow" data-car="0">
    <view class="middleMoney">￥{{shopInfoList.price}}</view>
    <view>单独购买</view>
  </view>
  <view class="right" @tap="popupshow" data-car="3">
    <view class="middleMoney">￥{{shopInfoList.group_price}}</view>
    <view>拼团购买</view>
  </view>
</view>
<!-- 选择规格 -->
<view class="mask-box" :hidden="popup">
  <view @tap.stop="popuphidden" style="width:100%;height:650rpx;"></view>
  <view class="mask-bot">
    <view>
      <view class="popup-warp">
        <view class="popup-pic fl">
          <image :src="isShowImg" :data-img="isShowImg" @tap.stop="lookPic"></image>
        </view>
        <view class="pop-warp fr">
          <view class="pop-title">
            <text>{{shopInfoList.name}}</text>
          </view>
          <view class="pop-current">
            ￥
            <text v-if="car ==0">{{isShowMoney}}</text>
            <text v-if="car ==3">{{shopInfoList.group_price}}</text>
          </view>
          <view class="pop-repertory fr">
            库存
            <text>{{shopInfoList.goods_number}}</text>
          </view>
        </view>
      </view>
    </view>
    <view v-for="(item, index) in specification" :key="index" class="spec-warp">
      <view class="spec">
        <text>{{item.spec_name}}</text>
      </view>
      <view class="option-warp">
        <view class="frame fl">
          <view>
            <block v-for="(item, index2) in item.spec_values" :key="index2">
              <text :class="item.isSelect?'op-active':'normal'" :data-select-index="id" :data-attr-index="index" :data-content="specification" @tap="clickMenu">{{item.spec_value}}</text>
            </block>
          </view>
        </view>
      </view>
    </view>
    <view class="count-warp">
      <view class="spec">
        <text>数量</text>
      </view>
      <view class="but">
        <text @tap="deleteShopNum">-</text>
        <text class="but-count">{{shopNum}}</text>
        <text @tap="addShopNum">+</text>
      </view>
    </view>
    <view class="btn-sure">
      <view class="confirm" @tap="optionsure">
        <text>确定</text>
      </view>
    </view>
  </view>
</view>
</view>
</template>

<script>
let goodsList = [{
  actEndTime: '2018-11-30 10:00:00'
}];
import api from "../../../api";
var app = getApp(); // var text;
// var text;
var guige = [];
var myGuige = null;
var countTime;

export default {
  data() {
    return {
      starNum: 5,
      // 倒计时数组
      overTime: [],
      // 判断活动是否结束
      isOver: true,
      userId: '',
      bannerList: [],
      shopId: '',
      // shopInitImg: '',
      shopInitPrice: '',
      // 请求参数
      requestShopId: '',
      // 选择规格判断默认图片&价格--选择好规格后的价格和图片
      isShowImg: '',
      isShowMoney: '',
      // 商品详情列表
      shopInfoList: [],
      // 商品数量
      shopNum: 1,
      // 商品规格列表
      specification: [],
      // 选择好的规格
      changeSpecification: [],
      // tab切换
      navList: ["详情", "评价"],
      // 规格选择列表
      poplist: [],
      idd: [],
      // 是否选择了规格 判断
      ischangespecification: '',
      // 加入购物车&购买
      car: '',
      boolean: false,
      imgUrls: ["/static/remao_shop/img/details-banner.png", "/static/remao_shop/img/details-banner.png"],
      countDownList: [],
      actEndTimeList: [],
      indicatorDots: true,
      autoplay: true,
      interval: 5000,
      duration: 1000,
      status: 0,
      pop: 0,
      showView: true,
      popup: true,
      // 判断是否为秒杀商品、不秒杀0.秒杀1
      ismiaosha: 1,
      orderType: '',
      // 拼团列表轮播参数
      indicatorDots: false,
      autoplay: true,
      //自动切换
      interval: 5000,
      //自动切换时间间隔	
      duration: 1000,
      //滑动动画时长	
      circular: true,
      //是否采用衔接滑动	(无缝轮播)
      vertical: true,
      //滑动方向是否为纵向	
      arrList: [],
      //处理前
      arrListArray: [],
      //处理后
      isAssemble: false,
      //更多拼团
      isCloseAssemble: '',
      //是否有人开团
      shareAssemble: '',
      //拼团分享订单id
      system: '',
      endTime: "",
      orderId: "",
      bannerLength: false,
      group_price: "",
      hidden: false
    };
  },

  components: {},
  props: {},
  onLoad: function (options) {
    var that = this; //判断系统

    wx.getSystemInfo({
      success: function (res) {
        console.log(res);

        if (res.platform == 'devtools') {
          that.setData({
            system: false
          });
        } else if (res.platform == 'ios') {
          that.setData({
            system: true
          });
        } else {
          that.setData({
            system: false
          });
        }
      }
    }); //收藏初始

    console.log(options);
    this.setData({
      shopId: options.goods_id // isShowImg: options.img

    });
    this.getlist();
    this.assemble();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  methods: {
    popupshow: function (e) {
      console.log(e);
      this.setData({
        car: e.currentTarget.dataset.car
      });
      this.setData({
        popup: false
      });

      if (this.car == 3) {
        this.setData({
          isShowMoney: this.group_price
        });
      } else if (this.car == 0) {
        this.setData({
          isShowMoney: this.shopInfoList.price
        });
      }
    },

    // 拼团列表
    assemble() {
      let that = this;
      app.globalData.request({
        url: api.fyz.assembleInfoList,
        data: {
          goods_id: that.shopId
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值

        },
        method: 'POST',
        success: res => {
          console.log(res);
          var endTime = [];

          for (let i = 0; i < res.data.length; i++) {
            endTime[i] = res.data[i].group_end_time;
          }

          that.setData({
            endTime: endTime
          });
          console.log(this.endTime);
          console.log(res.data, "107");

          if (res.data == "") {
            that.setData({
              isCloseAssemble: false
            });
          } else if (res.data.length == 1) {
            that.setData({
              arrList: res.data,
              arrListArray: res.data,
              isCloseAssemble: true
            });
          } else {
            // 让返回的数组*2让其长度为偶数
            let aabb = [];
            aabb = aabb.concat(res.data);
            aabb = aabb.concat(aabb);
            console.log(aabb); //创建二维数组，
            //第一个index是遍历swiper-item，
            //第二个是遍历swiper-item下的数据

            let arr = [];
            let arrs = [];
            let index = 0;

            for (let a = 0; a < aabb.length; a++) {
              var item = aabb[a];
              arr = arr.concat(item);

              if (arr.length % 2 == 0 && arr.length != 0) {
                arrs.push(arr);
                arr = [];
              }
            }

            console.log(arrs);
            that.setData({
              arrList: res.data,
              arrListArray: arrs,
              isCloseAssemble: true
            });
            console.log(this.arrListArray); // 计时器
          }

          countTime = setInterval(that.countDown, 1000);
        },
        fail: function (res) {},
        complete: function (res) {}
      });
    },

    // 评价星级
    star() {
      let that = this;
      let starArray = [];

      for (let a = 0; a < that.shopInfoList.comments.length; a++) {
        starArray.push(parseInt(that.shopInfoList.comments[a].star));
      }

      console.log(starArray);
      that.setData({
        starNum: starArray
      });
    },

    // 去参团
    joinAssemble(e) {
      let orderId = e.currentTarget.dataset.id;
      this.setData({
        orderId: orderId,
        car: 3
      });
      app.globalData.request({
        url: api.gzSea.examine,
        data: {
          order_id: orderId,
          user_id: this.userId
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值

        },
        method: 'POST',
        success: res => {
          console.log(res, "去参团");

          if (res.status == 0) {
            wx.showToast({
              title: res.msg,
              icon: "none"
            });
          } else if (res.status == 1) {
            this.popupshow(e);
          }

          this.setData({
            isAssemble: false
          });
        }
      });
    },

    //打开全部拼团列表
    isOpenAssemble() {
      this.setData({
        isAssemble: !this.isAssemble
      });
    },

    // 阻止点击事件冒泡专用方法
    kong() {},

    // 预览单张图片
    lookPic: function (e) {
      console.log(e.currentTarget.dataset.img);
      var picList = [];
      picList.push(e.currentTarget.dataset.img);
      wx.previewImage({
        current: picList[0],
        // 当前显示图片的http链接
        urls: picList // 需要预览的图片http链接列表

      });
    },
    // 预览多张图片
    lookPics: function (e) {
      console.log(e.currentTarget.dataset.img);
      var picList = [];
      picList.push(e.currentTarget.dataset.img);
      wx.previewImage({
        current: picList[0],
        // 当前显示图片的http链接
        urls: picList // 需要预览的图片http链接列表

      });
    },
    //消失
    popuphidden: function () {
      this.setData({
        popup: true
      });
    },
    // 选择规格
    clickMenu: function (event) {
      let that = this; // console.log(event)

      let selectIndex = event.currentTarget.dataset.selectIndex;
      let attrIndex = event.currentTarget.dataset.attrIndex;
      let content = event.currentTarget.dataset.content;
      var count = content[selectIndex].spec_values.length;

      for (var i = 0; i < count; i++) {
        content[selectIndex].spec_values[i].isSelect = false;
      }

      content[selectIndex].spec_values[attrIndex].isSelect = true; // // 必须重新渲染数据----------为了添加isSelect属性

      that.setData({
        specification: content
      }); // 选择规格

      if (selectIndex == 0) {
        guige[0] = this.specification[0].spec_values[attrIndex].spec_value_id;
      } else if (selectIndex == 1) {
        guige[1] = this.specification[1].spec_values[attrIndex].spec_value_id;
      } else if (selectIndex == 2) {
        guige[2] = this.specification[2].spec_values[attrIndex].spec_value_id;
      }

      console.log(guige);

      if (this.specification.length == 1) {
        myGuige = guige[0];
      } else if (this.specification.length == 2) {
        myGuige = guige[1] + '_' + guige[0];
      } else if (this.specification.length == 3) {
        myGuige = guige[2] + '_' + guige[1] + '_' + guige[0];
      }

      console.log();
      console.log(myGuige); // 遍历所有可用规格并进行匹配

      for (let item in this.shopInfoList.sys_attrprice) {
        if (myGuige == item) {
          // 显示对应的价格和图片
          let showguige1 = this.shopInfoList.sys_attrprice[myGuige].pic;
          let showguige2 = this.shopInfoList.sys_attrprice[myGuige].price;
          this.setData({
            isShowMoney: showguige2
          });

          if (showguige1 != '') {
            this.setData({
              isShowImg: showguige1
            });
          }
        }
      }
    },

    // 增加商品数量
    addShopNum() {
      if (this.shopNum < this.shopInfoList.goods_number) {
        this.setData({
          shopNum: this.shopNum + 1
        });
      } else {
        wx.showToast({
          title: '抱歉亲，库存不够了呢！',
          duration: 2000,
          icon: 'none'
        });
      }
    },

    // 减少商品数量
    deleteShopNum() {
      if (this.shopNum > 1) {
        this.setData({
          shopNum: this.shopNum - 1
        });
      } else {
        wx.showToast({
          title: '亲，购买数量不能再减了哦！',
          duration: 2000,
          icon: 'none'
        });
      }
    },

    //点击确定
    optionsure(e) {
      let that = this;
      let a = wx.getStorageSync("userId");
      console.log(a);

      if (a == '') {
        wx.switchTab({
          url: '../../pages/mine/mine'
        });
      } else {
        that.setData({
          userId: a
        });

        if (this.specification.length != 0 && myGuige == null) {
          wx.showToast({
            title: '请选择规格',
            icon: 'none',
            duration: 1000
          });
        } //  else {
        //    if (myGuige.indexOf("undefined") != -1) {
        //     wx.showToast({
        //       title: '请选择规格',
        //       icon: 'none',
        //       duration: 1000,
        //     })
        //   } 
        else {
            // 判断库存够不够
            if (this.shopNum > this.shopInfoList.goods_number) {
              wx.showToast({
                title: '亲，库存不够了呢',
                icon: 'none',
                duration: 1000
              });
            } else {
              // 购物车
              if (this.specification.length == 1) {
                var myGuigecart = guige[0];
              } else if (this.specification.length == 2) {
                var myGuigecart = guige[1] + ',' + guige[0];
              } else if (this.specification.length == 3) {
                var myGuigecart = guige[2] + ',' + guige[1] + ',' + guige[0];
              }

              console.log(myGuigecart);
              console.log(that.car);
              app.globalData.request({
                url: api.fyz.add_cart,
                data: {
                  goods_id: that.shopId,
                  uid: that.userId,
                  goods_number: that.shopNum,
                  spec_value_id: myGuigecart,
                  type: 2
                },
                header: {
                  'content-type': 'application/x-www-form-urlencoded' // 默认值

                },
                method: 'POST',
                dataType: 'json',
                responseType: 'text',
                success: res => {
                  console.log(res);

                  if (res.status == 1) {
                    wx.showToast({
                      title: res.msg,
                      duration: 2000
                    });
                    setTimeout(function () {
                      that.setData({
                        popup: true
                      });
                    }, 2000); // wx.showToast({
                    //   title: res.data.msg,
                    //   duration: 1000
                    // });
                    // setTimeout(function () {

                    console.log(res.cart_id);
                    wx.navigateTo({
                      url: '../affirm/affirm?userId=' + that.userId + '&cart_id=' + res.cart_id + '&type=' + 2 + '&ismiaosha=' + 1 + '&order_type=' + 3 + "&oid=" + this.orderId
                    });
                    that.setData({
                      popup: true
                    }); // }, 1000)
                  } else {
                    wx.showToast({
                      title: res.msg,
                      duration: 2000
                    });
                  }
                },
                fail: function (res) {},
                complete: function (res) {}
              });
            }
          } // }

      } // this.setData({ popup: true })

    },

    // 加载商品详情
    getlist: function () {
      var that = this;
      var uid = wx.getStorageSync("userId");
      that.setData({
        userId: uid
      });
      app.globalData.request({
        url: api.fyz.shopInfo,
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值

        },
        method: 'POST',
        data: {
          goods_id: that.shopId,
          user_id: that.userId
        },
        success: res => {
          console.log(res);
          var length = res.pic.length;

          if (length == 1) {
            this.setData({
              bannerLength: false
            });
          } else {
            this.setData({
              bannerLength: true
            });
          }

          this.setData({
            group_price: res.group_price,
            bannerList: res.pic,
            shopInfoList: res,
            specification: res.specification,
            isShowMoney: res.price,
            isShowImg: res.thumb_img
          });
          that.star(); // 判断该商品是否收藏
          // if (res.is_collect == 0) {
          //   this.setData({
          //     showView: true
          //   })
          // } else if (res.is_collect == 1) {
          //   this.setData({
          //     showView: false
          //   })
          // }

          console.log(that.showView);
        },
        fail: function (res) {},
        complete: function (res) {}
      });
    },

    //详情评价切换点击事件
    getStatus(e) {
      this.setData({
        status: e.currentTarget.dataset.index,
        hidden: false
      });
    },

    // 收藏商品
    changepic: function () {
      wx.switchTab({
        url: '../../pages/index/index'
      }); // var that = this;
      // if (that.isLogin() == 0) {
      //   wx.switchTab({
      //     url: '../../pages/mine/mine',
      //   })
      // } else {
      //   that.setData({
      //     userId: wx.getStorageSync("userId")
      //   })
      //   app.request({
      //     url: api.fyz.shopCollection,
      //     data: {
      //       goods_id: this.data.shopId,
      //       user_id: that.data.userId
      //     },
      //     header: {
      //       'content-type': 'application/x-www-form-urlencoded' // 默认值
      //     },
      //     method: 'POST',
      //     success: (res) => {
      //       console.log(res)
      //       wx.showToast({
      //         title: res.msg,
      //         duration: 1000
      //       })
      //       that.setData({
      //         showView: (!that.data.showView)
      //       })
      //     },
      //     fail: function(res) {},
      //     complete: function(res) {},
      //   })
      // }
    },

    // 跳转购物车
    toShopCar() {
      wx.switchTab({
        url: '../../pages/trolley/trolley'
      });
    },

    // 判断是否登录
    isLogin() {
      if (wx.getStorageSync("userId") == '') {
        return 0;
      } else {
        return 1;
      }
    },

    banner(e) {
      console.log(this.bannerList);
      var list = [],
          index = e.currentTarget.dataset.index;
      console.log(e);

      for (var i = 0; i < this.bannerList.length; i++) {
        list[i] = this.bannerList[i].big;
      }

      wx.previewImage({
        current: list[index],
        urls: list // 需要预览的图片http链接列表

      });
    },

    // 倒计时
    countDown() {
      for (let i = 0; i < this.endTime.length; i++) {
        let endTime = parseInt(this.endTime[i]);
        let nowTime = parseInt(new Date().getTime() / 1000); //console.log(nowTime, endTime)

        let time = endTime - nowTime;
        var hour = parseInt(time / 60 / 60 % 24); //console.log(hour)

        if (String(hour).length == 1) {
          hour = '0' + hour;
        }

        var minute = parseInt(time / 60 % 60);

        if (String(minute).length == 1) {
          minute = '0' + minute;
        }

        var seconds = parseInt(time % 60);

        if (String(seconds).length == 1) {
          seconds = '0' + seconds;
        } // console.log(hour, minute, seconds)


        let timer = []; //所有时间数组

        timer[0] = hour;
        timer[1] = minute;
        timer[2] = seconds; // console.log(timer)

        if (time > 0) {
          //判断如果时间过期则改变
          this.setData({
            overTime: timer,
            isOver: true
          });
        } else {
          clearInterval(countTime);
          this.setData({
            isOver: false
          });
        }
      }
    }

  }
};
</script>
<style>
@import "./groupdetails.css";
</style>